using System;
using System.Text;
using NHibernate.Exceptions;
using Rubikev.Common.Data;

namespace Rubikev.NHibernate
{
   public class GenericAdoExceptionConverter : ISQLExceptionConverter
   {
      public Exception Convert(AdoExceptionContextInfo adoExceptionContextInfo)
      {
         StringBuilder message = new StringBuilder();
         message.AppendLine(adoExceptionContextInfo.Message);
         message.AppendLine("Using SQL:");
         message.AppendLine(adoExceptionContextInfo.Sql);
         return new InvalidEntityException(message.ToString(), adoExceptionContextInfo.SqlException);
      }
   }
}